<!-- 考试  ks.jsp -->
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<html>
	<head>
		<script type="text/javascript" src="<%=contextPath%>/js/validator.js"></script> 
		<script type="text/javascript" src="<%=contextPath%>/js/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" language="javascript"> 
		
			// 人行号
			var usernum = 0;
			<c:if test="${ksryList != null || fn:length(ksryList) != 0 }">
				usernum = ${fn:length(ksryList)};
			</c:if>
				
			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				        {
				            text: '保存',
				            icon:"<%=contextPath%>/images/save.gif",
				            handler:toCheck
				        },'-',
				        {
				            text: '返回',
				            icon:"<%=contextPath%>/images/fanhui.png",
				            handler:function(){
				            		back();
				            }
				        }
			    	]
			    });
			});
			
						String.prototype.endWith=function(str){
				if(str==null||str==""||this.length==0||str.length>this.length)
				return false;
				if(this.substring(this.length-str.length)==str)
				return true;
				else
				return false;
				return true;
				}
		
			function toCheck(){

			  	if(!Validator.Validate(frmM,2)){
				  return false;
			  	}

				var str1 = 0;
				var msg = "";
	
				for (var i = 0; i < frmM.elements.length; i++)
				{
					var e = frmM.elements[i];
					e.style.backgroundColor = "white";

				    if (e.name.endWith("ksfs")) {
				    	if (!validateDouble(e)) {
				    		e.style.backgroundColor="yellow";
				    		++str1;
				    	}
				    }
				    
				}

				if (str1 > 0) {
					msg +=  "黄色底色框必须输入，请输入0～100，两位小数最多2位。";
				}
				
				if (msg.length > 0) {
					alert("系统检测到您的提交有以下错误：\t\t\t\t\n" + msg);
					return;
				}

  				comt();
  			
		    }   
			/*
			 * 小数点2位验证
			 */
			function validateDouble(ctl) {
			  var n = ctl.value; 
			  var reg = /(^[1-9]{1}\d{0,1}$)|(^100$)|(^0$)|(^0\.\d{1,2}$)|(^([1-9]{1}\d{0,1}){1,1}(\.){1,1}(\d{1,2}){1,1}$)$/;
			  return reg.test(n);
			}		    

		 </script>  
	</head>
	<body >
		<div id = "tbar"></div>
		<br>
		<!-- 信息提示 -->
		<div id="result" align="center"><font color="red">${info }</font></div>
		<table width="100%" height="30">
			<tr>
				<td colspan="4" align="center">
					<c:if test="${searchBean.con1 == '0'}">
						培训记录
					</c:if>
					<c:if test="${searchBean.con1 == '1'}">
						考试记录
					</c:if>					
				</td>
			</tr>
		</table>
		<form id="frmM" name="frmM" method="POST" action="<%=contextPath%>/ks!save.do">
			<s:hidden name="entity.id" />
			<s:hidden name="entity.state" />
			<s:hidden name="userid" />
			<s:hidden name="username" />
			<s:hidden name="bdz" value="1" />
			<table width="100%" id="infotab">
				<tr>
					<th width="120" >
						<font color="red">*</font>&nbsp;
						<c:if test="${searchBean.con1 == '0'}">
						培训开始时间：
					    </c:if>
					    <c:if test="${searchBean.con1 == '1'}">
						考试开始时间：
					    </c:if>
					</th>
					<td>
						<input type="text" onclick="WdatePicker({el:$dp.$('entity.kssj')})" name="entity.kssj" datatype="Require" readonly="true" value='<fmt:formatDate value="${entity.kssj}" pattern="yyyy-MM-dd HH:mm"/>' msg="考试开始时间必须输入。"/>
						<img onclick="WdatePicker({el:$dp.$('entity.kssj')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					</td>
					<th width="120" >
						<font color="red">*</font>&nbsp;
						<c:if test="${searchBean.con1 == '0'}">
						培训结束时间：
					    </c:if>
					    <c:if test="${searchBean.con1 == '1'}">
						考试结束时间：
					    </c:if>
					</th>
					<td>
						<input type="text" onclick="WdatePicker({el:$dp.$('entity.jssj')})" name="entity.jssj" datatype="Require" readonly="true" value='<fmt:formatDate value="${entity.jssj}" pattern="yyyy-MM-dd HH:mm"/>' msg="考试结束时间必须输入。"/>
						<img onclick="WdatePicker({el:$dp.$('entity.jssj')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					</td>
				</tr>
				<tr>
					<th width="120" >
						<font color="red">*</font>&nbsp;
						<c:if test="${searchBean.con1 == '0'}">
						培训地点：
					    </c:if>
					    <c:if test="${searchBean.con1 == '1'}">
						考试地点：
					    </c:if>
					</th>
					<td nowrap>
						<input type="text" style="width:50%" name="entity.ksdd" datatype="Require" value="${entity.ksdd}" msg="考试地点称必须输入。" maxlength="100"/>
					</td>
					<th>
						<font color="red">*</font>&nbsp;培训员：
					</th>
					<td nowrap>
						<input type="text" style="width:50%" name="entity.pxy" datatype="Require" value="${entity.pxy}" msg="培训员必须输入。" maxlength="50"/>
					</td>
				</tr>
				<tr>
					<th width="120" nowrap>
					<c:if test="${searchBean.con1 == '0'}">
						培训计划：
					</c:if>
					<c:if test="${searchBean.con1 == '1'}">
						考试计划：
					</c:if>	
					</th>
					<td colspan="3">
						<textarea style="width:99%; height: 30px; min-height: 20px;line-height:15pt"  min="0" datatype="LimitB"  max="1000" name="entity.pxjh"  >${entity.pxjh}</textarea>
					</td>
				</tr>
					<th style="width:10%" >
						附件：
					</th>
					<td colspan="3">
						<c:if test="${entity.id != '0'}">
							<img hef="#" style='cursor:pointer' onclick="filePopup('${entity.id}','TAB_KS_FJ','0')" alt="打开附件列表" src="<%=contextPath%>/images/userfile.png" >
						</c:if>
						<c:if test="${entity.id == '0'}">
							&nbsp;<img src="<%=contextPath%>/images/redlight.gif"/><font color="red">请保存记录后上传附件</font>
						</c:if>
					</td>				
				<tr>
					<th width="120" nowrap>
					<c:if test="${searchBean.con1 == '0'}">
						培训内容：
					</c:if>
					<c:if test="${searchBean.con1 == '1'}">
						考试内容：
					</c:if>	
					</th>
					<td colspan="3">
						<textarea style="width:99%; height: 30px; min-height: 20px;line-height:15pt"  min="0" datatype="LimitB"  max="1000" name="entity.pxnr"  >${entity.pxnr}</textarea>
					</td>
				</tr>
				<tr>
					<th width="120" nowrap>
					<c:if test="${searchBean.con1 == '0'}">
						培训方式：
					</c:if>
					<c:if test="${searchBean.con1 == '1'}">
						考试方式：
					</c:if>
					</th>
					<td colspan="3">
						<textarea style="width:99%; height: 30px; min-height: 20px;line-height:15pt"  min="0" datatype="LimitB"  max="1000" name="entity.pxfs"  >${entity.pxfs}</textarea>
					</td>
				</tr>

			</table>

			<hr>
			<table width="100%" id="listtab" class = "leadertab" >
				<tr>
					<th width="120"><a href="#" onClick="javascript:getKsry('userid','username','bdz')"><img src="<%=contextPath%>/images/user_suit.png" alt="追加参培人员" style='cursor:pointer'/>人员选择</a></th>
					<th   width="120">序号</th>
					<th   width="150">参培人员</th>
					<th><c:if test="${searchBean.con1 == '1'}">分数</c:if>
					</th>
				</tr>

				<c:forEach items="${ksryList}" var="detail" varStatus="status">
					<tr id='tr${status.index}' class = "repeat">
						<th width="120"><img src="<%=contextPath%>/images/delete.gif" onclick = "delrow(this,${detail.id})" style="cursor:pointer"/></th>
						<td width="120" id='td${status.index}'>
								<script language="javascript">document.write(parseInt('${status.index}') + parseInt(1))</script>
						</td>
						<td width="150">&nbsp;${detail.username}</td>
						<td >
							&nbsp;
							<c:if test="${searchBean.con1 == '1'}"><input type="text" id="ksryList[${status.index}].ksfs" name="ksryList[${status.index}].ksfs"  maxlength="5" value = "${detail.ksfs}"/></c:if>
							<input type="hidden" id="ksryList[${status.index}].userid" name="ksryList[${status.index}].userid" value = "${detail.userid}"/>
							<input type="hidden" id="ksryList[${status.index}].username" name="ksryList[${status.index}].username" value = "${detail.username}"/>
							<input type="hidden" id="ksryList[${status.index}].id" name="ksryList[${status.index}].id" value = "${detail.id}"/>
							<input type="hidden" id="ksryList[${status.index}].ksid" name="ksryList[${status.index}].ksid"/>
						</td>

					</tr>
				</c:forEach>
			
			</table>
		</form>
	</body>
</html>
<script language="javascript">

	 // 保存
     function comt(){
     	document.frmM.action = "<%=contextPath%>/ks!save.do";
     	document.frmM.submit();
     }
     
     // 返回
     function back() {
     	document.frmM.action = "<%=contextPath%>/ksList!getList.do";
		document.frmM.submit();
     }

	 // 查询
	 function cmt(){
		document.frmM.action = "<%=contextPath%>/ksList!getList.do?page=1";
		document.frmM.submit();
	 }
	 

	 
	 // 增加行
	 function setHTML(userid, username) {

	 	// 如果已存在用户不添加
		for (var index=0;index<usernum; index++) {
			if (document.getElementById("ksryList[" + index + "].userid") != null && document.getElementById("ksryList[" + index + "].userid").value == userid) {
				return;
			}
		}
		
		//window.alert(${entity.state});
		var str ='';
		if(${entity.state}==1){
		 str = 	'<tr id = '+ usernum +' class = "repeat">' +
					'<td width="120"><img src="/DLMIS/images/delete.gif" onclick = "delrow(this,0)" style="cursor:pointer"/></td>' + 
					'<td width="120" id="td' + usernum + '">' + usernum + '</td>' + 
					'<td width="150">&nbsp;' + username + '</td>' + 
					'<td >&nbsp;<input type="text" id=ksryList['+ usernum + '].ksfs name=ksryList['+ usernum + '].ksfs maxlength="5" />' +
					'<input type="hidden" id=ksryList['+ usernum + '].id name=ksryList['+ usernum + '].id value ="0">' +
					'<input type="hidden" id=ksryList['+ usernum + '].ksid name=ksryList['+ usernum + '].ksid value ="0">' +
					'<input type="hidden" id=ksryList['+ usernum + '].userid name=ksryList['+ usernum + '].userid value =' + userid + '>' +
					'<input type="hidden" id=ksryList['+ usernum + '].username name=ksryList['+ usernum + '].username value =' + username + '></td>' + 
					'</tr>';
					}else{
					str = 	'<tr id = '+ usernum +' class = "repeat">' +
					'<td width="120"><img src="/DLMIS/images/delete.gif" onclick = "delrow(this,0)" style="cursor:pointer"/></td>' + 
					'<td width="120" id="td' + usernum + '">' + usernum + '</td>' + 
					'<td width="150">&nbsp;' + username + '</td>' + 
					'<td >&nbsp;' +
					'<input type="hidden" id=ksryList['+ usernum + '].id name=ksryList['+ usernum + '].id value ="0">' +
					'<input type="hidden" id=ksryList['+ usernum + '].ksid name=ksryList['+ usernum + '].ksid value ="0">' +
					'<input type="hidden" id=ksryList['+ usernum + '].userid name=ksryList['+ usernum + '].userid value =' + userid + '>' +
					'<input type="hidden" id=ksryList['+ usernum + '].username name=ksryList['+ usernum + '].username value =' + username + '></td>' + 
					'</tr>';
					}
					
		$('table.leadertab').append(str);	
				
		usernum++;
		
		// 重新付序号
		var n = 0;		
		for (var index=0;index<usernum; index++) {
			if (document.getElementById("td" + index) != null && document.getElementById("td" + index) != undefined) {
				++n;
				document.getElementById("td" + index).innerHTML = n;
			}
		}				
	 }
	 
	// 获得用户
	function getKsry(userid, username,bdz) {
	
		document.getElementById("userid").value = "";
		document.getElementById("username").value = "";
	
		for (var index=0;index<usernum; index++) {
			if (document.getElementById("ksryList["+ index + "].userid") != null) {
				document.getElementById("userid").value += document.getElementById("ksryList["+ index + "].userid").value +  ",";
				document.getElementById("username").value += document.getElementById("ksryList["+ index + "].userid").value +  ",";
			}
		}
		var url = "<%=contextPath%>/jsp/popup/userCheckBox2Popup.jsp?userid="+ userid +"&username=" + username;
        var win = openSUB(url,2,300,520,450,30);  //4 有滚动条
	}	
	
	//删除一行（已有数据）
	function delrow(row,id){


		if (confirm("确定要删除该培训人员吗？")) {
			if(id != 0) {
				Ext.Ajax.request({
					method :'POST',
					url :'ks!deleteKsRy.do?id=' + id,
					params : {},
					success : function(response, options) {
						var obj = Ext.decode(response.responseText);
						Ext.MessageBox.alert('提示', obj["msg"]);
					
	   					$(row).parents(".repeat").remove();	
	   
						// 重新付序号
						var n = 0;		
						for (var index=0;index<usernum; index++) {
							if (document.getElementById("td" + index) != null && document.getElementById("td" + index) != undefined) {
							++n;
							document.getElementById("td" + index).innerHTML = n;
							}
						}	
					},
					failure : function(response, options) {
						Ext.MessageBox.alert('提示 ', '删除失败。');
					}
				});
			} else {
	   			$(row).parents(".repeat").remove();	
	   
				// 重新付序号
				var n = 0;		
				for (var index=0;index<usernum; index++) {
					if (document.getElementById("td" + index) != null && document.getElementById("td" + index) != undefined) {
						++n;
						document.getElementById("td" + index).innerHTML = n;
					}
				}	
			}

		}

	} 
</script>